﻿
using System;
using System.Collections;
using System.Web.UI.WebControls;

namespace GiftNet.Model
{
	#region PayLog Model -(by fangyifeng at 2013/12/28 17:18:57)

	/// <summary>
	/// PayLog object'PayLog'.
	/// </summary>
	public class PayLog : System.IComparable
		{
		#region Member Variables
		
		protected Guid _id;
		protected decimal _payAmount;
		protected DateTime _payTime;
		protected string _payRecord;
		protected string _remark;
		protected FactoryOrder _factoryOrder;
		
		protected static String _sortExpression = "Id";
		protected static SortDirection _sortDirection = SortDirection.Ascending;

		#endregion

		#region Constructors

		public PayLog() { }

		public PayLog( decimal payAmount, DateTime payTime, string payRecord, string remark, FactoryOrder factoryOrder )
		{
			this._payAmount = payAmount;
			this._payTime = payTime;
			this._payRecord = payRecord;
			this._remark = remark;
			this._factoryOrder = factoryOrder;
		}

		#endregion

		#region Public Properties

		public virtual Guid Id
		{
			get {return _id;}
			set {_id = value;}
		}

		public virtual decimal PayAmount
		{
			get { return _payAmount; }
			set { _payAmount = value; }
		}

		public virtual DateTime PayTime
		{
			get { return _payTime; }
			set { _payTime = value; }
		}

		public virtual string PayRecord
		{
			get { return _payRecord; }
			set
			{
				if ( value != null && value.Length > 250)
					throw new ArgumentOutOfRangeException("Invalid value for PayRecord", value, value.ToString());
				_payRecord = value;
			}
		}

		public virtual string Remark
		{
			get { return _remark; }
			set
			{
				if ( value != null && value.Length > 500)
					throw new ArgumentOutOfRangeException("Invalid value for Remark", value, value.ToString());
				_remark = value;
			}
		}

		public virtual FactoryOrder FactoryOrder
		{
			get { return _factoryOrder; }
			set { _factoryOrder = value; }
		}

		
        public static String SortExpression
        {
            get { return _sortExpression; }
            set { _sortExpression = value; }
        }

        public static SortDirection SortDirection
        {
            get { return _sortDirection; }
            set { _sortDirection = value; }
        }
		#endregion
		
        #region IComparable Methods
        public virtual int CompareTo(object obj)
        {
			if (!(obj is PayLog))
				throw new InvalidCastException("This object is not of type PayLog");
			
			int relativeValue;
			switch (SortExpression)
			{
				case "Id":
					relativeValue = this.Id.CompareTo(((PayLog)obj).Id);
					break;
				case "PayAmount":
					relativeValue = this.PayAmount.CompareTo(((PayLog)obj).PayAmount);
					break;
				case "PayTime":
					relativeValue = this.PayTime.CompareTo(((PayLog)obj).PayTime);
					break;
				case "PayRecord":
					relativeValue = this.PayRecord.CompareTo(((PayLog)obj).PayRecord);
					break;
				case "Remark":
					relativeValue = (this.Remark != null) ? this.Remark.CompareTo(((PayLog)obj).Remark) : -1;
					break;
                default:
                    goto case "Id";
			}
            if (PayLog.SortDirection == SortDirection.Ascending)
				relativeValue *= -1;
			return relativeValue;
		}
		#endregion
	}

	#endregion
}
